<?php
/**
 * @author Admin
 *
 *
 */
class TraversableDisplay extends Display {
	protected $ctr=0;
	protected $numToDisplay=1;
	protected $children;
	protected $navigation;
	/**
	 *	Used to add iterator controls
	 *  to a collection of displays
	 */
	public function __construct($base = NULL,DisplayCollection $collection = NULL,$limit=1 ) {
		if( $base == NULL ){
			$this->base =  "traversibleCollectionTemplate";
		}
		$this->styles = 'SharedSkins';
		$this->navigation = new PageNavigator("nav","nav grid_11");
		$this->navigation->limit = $limit;
		$this->navigation->collectionTotal = count($collection);
		if($collection instanceof DisplayCollection ){
			$this->children = $collection;
		}
		else {
			$this->children = new DisplayCollection();
		}
		parent::__construct( $base = NULL );
	}
	
	/**
	 *
	 * adds a child display to this composite
	 * @param Display $display
	 */
	public function addChild( Display  $display,$token = "" ){
		$this->children->addElement($display);
	}
	
 	public function finalize(){
 		$buffer = "";
 		$this->navigation->collectionTotal = $this->children->size();
 		$this->navigation->finalize();
		$this->nav = $this->navigation->output->content;
// 		print_r($this->navigation);
 		foreach ( $this->children as $child  ){
 			$child->finalize();
 			$buffer.=$child->content;
 			$this->ctr++;
 		}
 		$this->childoutput=$buffer; 
 		parent::finalize();
 	}
}


?>